package com.xyzh05.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;

@Entity
@Table(name="login_log")
@Searchable
@XmlRootElement
public class LoginLog extends BaseObject implements Serializable {
	
	public static final Short MODE_PC = 1;
	public static final Short MODE_MOBILE = 2;
	
	public static final Short LOCATION_HOME = 1;
	public static final Short LOCATION_OFFICE = 2;
	public static final Short LOCATION_OTHER = 3;
	
    private Long id;
    private Long userId;
    private Date loginTime;
    private Date logoutTime;
    private String country;
    private String province;
    private String city;
    private String address;
    private Short location;
    private Short mode;
    private String ip;

    @Id @GeneratedValue(strategy=GenerationType.AUTO) @SearchableId    
    public Long getId() {
        return this.id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    @Column(name="user_id", nullable=false)
    @SearchableProperty
    public Long getUserId() {
        return this.userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="login_time", nullable=false, length=19)
    @SearchableProperty
    public Date getLoginTime() {
        return this.loginTime;
    }
    
    public void setLoginTime(Date loginTime) {
        this.loginTime = loginTime;
    }
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="logout_time", nullable=false, length=19)
    @SearchableProperty
    public Date getLogoutTime() {
        return this.logoutTime;
    }
    
    public void setLogoutTime(Date logoutTime) {
        this.logoutTime = logoutTime;
    }
    
    @Column(name="country", length=20)
    @SearchableProperty
    public String getCountry() {
        return this.country;
    }
    
    public void setCountry(String country) {
        this.country = country;
    }
    
    @Column(name="province", length=20)
    @SearchableProperty
    public String getProvince() {
        return this.province;
    }
    
    public void setProvince(String province) {
        this.province = province;
    }
    
    @Column(name="city", length=20)
    @SearchableProperty
    public String getCity() {
        return this.city;
    }
    
    public void setCity(String city) {
        this.city = city;
    }
    
    @Column(name="address", length=50)
    @SearchableProperty
    public String getAddress() {
        return this.address;
    }
    
    public void setAddress(String address) {
        this.address = address;
    }
    
    @Column(name="location")
    @SearchableProperty
    public Short getLocation() {
        return this.location;
    }
    
    public void setLocation(Short location) {
        this.location = location;
    }
    
    @Column(name="mode")
    @SearchableProperty
    public Short getMode() {
        return this.mode;
    }
    
    public void setMode(Short mode) {
        this.mode = mode;
    }
    
    @Column(name="ip", nullable=false, length=20)
    @SearchableProperty
    public String getIp() {
        return this.ip;
    }
    
    public void setIp(String ip) {
        this.ip = ip;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        LoginLog pojo = (LoginLog) o;

        if (userId != null ? !userId.equals(pojo.userId) : pojo.userId != null) return false;
        if (loginTime != null ? !loginTime.equals(pojo.loginTime) : pojo.loginTime != null) return false;
        if (logoutTime != null ? !logoutTime.equals(pojo.logoutTime) : pojo.logoutTime != null) return false;
        if (country != null ? !country.equals(pojo.country) : pojo.country != null) return false;
        if (province != null ? !province.equals(pojo.province) : pojo.province != null) return false;
        if (city != null ? !city.equals(pojo.city) : pojo.city != null) return false;
        if (address != null ? !address.equals(pojo.address) : pojo.address != null) return false;
        if (location != null ? !location.equals(pojo.location) : pojo.location != null) return false;
        if (mode != null ? !mode.equals(pojo.mode) : pojo.mode != null) return false;
        if (ip != null ? !ip.equals(pojo.ip) : pojo.ip != null) return false;

        return true;
    }

    public int hashCode() {
        int result = 0;
        result = (userId != null ? userId.hashCode() : 0);
        result = 31 * result + (loginTime != null ? loginTime.hashCode() : 0);
        result = 31 * result + (logoutTime != null ? logoutTime.hashCode() : 0);
        result = 31 * result + (country != null ? country.hashCode() : 0);
        result = 31 * result + (province != null ? province.hashCode() : 0);
        result = 31 * result + (city != null ? city.hashCode() : 0);
        result = 31 * result + (address != null ? address.hashCode() : 0);
        result = 31 * result + (location != null ? location.hashCode() : 0);
        result = 31 * result + (mode != null ? mode.hashCode() : 0);
        result = 31 * result + (ip != null ? ip.hashCode() : 0);

        return result;
    }

    public String toString() {
        StringBuffer sb = new StringBuffer(getClass().getSimpleName());

        sb.append(" [");
        sb.append("id").append("='").append(getId()).append("', ");
        sb.append("userId").append("='").append(getUserId()).append("', ");
        sb.append("loginTime").append("='").append(getLoginTime()).append("', ");
        sb.append("logoutTime").append("='").append(getLogoutTime()).append("', ");
        sb.append("country").append("='").append(getCountry()).append("', ");
        sb.append("province").append("='").append(getProvince()).append("', ");
        sb.append("city").append("='").append(getCity()).append("', ");
        sb.append("address").append("='").append(getAddress()).append("', ");
        sb.append("location").append("='").append(getLocation()).append("', ");
        sb.append("mode").append("='").append(getMode()).append("', ");
        sb.append("ip").append("='").append(getIp()).append("'");
        sb.append("]");
      
        return sb.toString();
    }

}
